<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
    <#include "/common/elibs.html">
</head><body><div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="${request.contextPath}/index">首页</a>
        <a href="#">资源类型管理</a>
        <a>
          <cite>列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div><div class="x-body">
    <div class="layui-row">
        <table class="layui-hide" id="test" lay-filter="test"></table>

        <!-- 操作列 -->
        <script type="text/html" id="oper-col">
            <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
    </div></div><script>
    isToken();
    layui.config({
        base: path+'/admin/treetable/'
    }).extend({
        treetable: 'treetable'
    });
    layui.use(['layer', 'table', 'treetable'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        var treetable = layui.treetable;

        // 渲染表格
        var renderTable = function () {
            layer.load(2);
            treetable.render({
                treeColIndex: 1,
                treeSpid: 0,
                treeIdName: 'idFileCabinet',
                treePidName: 'parent',
                treeDefaultClose: false,
                treeLinkage: false,
                elem: '#test',
                url: path+'/pc/fileCabinet/getFileList',
                page: false,
                cols: [[
                    {type: 'numbers'},
                    {field: 'name', title: '文件名称'},
                    {field: 'type', title: '文件类型',width: 150,templet: function (d) {
                            if (d.type == '0') {
                                return '文件夹';
                            }
                            if (d.type == '1') {
                                return '文件';
                            } else {
                                return '<span class="layui-badge-rim">菜单</span>';
                            }
                        }},
                    {field: 'level', title: '文件级别'},
                    {field: 'createTime', title: '创建时间',width:220},
                    {field: 'type', title: '操作类型',templet: function (d) {
                        if (d.type == '0') {
                            return '<a class="layui-btn layui-btn-primary  layui-btn-xs" lay-event="add">添加</a>';
                        }else{
                            return '';
                        }
                    }},
                    {templet: '#oper-col', title: '操作'}
                ]],
                done: function () {
                    layer.closeAll('loading');
                }
            });
        };

        renderTable();


        //监听工具条
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'del') {
                layer.msg('删除' + data.idFileCabinet);
                layer.confirm('真的删除行么', function (index) {
                    var params = {
                        "idFileCabinet": data.idFileCabinet
                    }
                    console.log(params);
                    if (true) {
                        $.ajax({
                            url: path + '/pc/fileCabinet/deleteFileInfo',
                            type: 'post',
                            // contentType: 'application/json',
                            // processData: false,
                            // dataType: 'json',
                            data: params,
                            success: function (datas) {
                                if (datas.code != 0) {
                                    layer.open({
                                        title: '提示信息'
                                        , content: datas.message
                                    });
                                } else {
                                    $(".layui-form-checked").not('.header').parents('tr').remove();
                                    layer.msg('删除成功', {icon: 1});
                                    obj.del();
                                    layer.close(index);
                                    console.log("success !");
                                }
                            },
                            traditional: true
                        });
                    }
                });
            } else if (layEvent === 'edit') {
                if(data.type == "0"){
                    window.location.href = '${request.contextPath}/modules/fileCabinet/editType.html?id=' + data.idFileCabinet;
                }else if(data.type == "1"){
                    window.location.href = '${request.contextPath}/modules/fileCabinet/editFile.html?id=' + data.idFileCabinet;
                }
            } else if (layEvent === 'add') {
                if(data.level < 3){
                    window.location.href = '${request.contextPath}/modules/fileCabinet/addType.html?id=' + data.idFileCabinet;
                }else if(data.level == "3"){
                    window.location.href = '${request.contextPath}/modules/fileCabinet/addFile.html?id=' + data.idFileCabinet;
                }else{
                    layer.open({
                        title: '提示信息'
                        , content: '文件级别不正确'
                    });
                }
            }
        });
    });
</script></body></html>